Skip to content

Comments

fix: improve getErrorDescFromResponse() performance#4110

Merged
logachev merged 5 commits intomainfrom
kirl/retry_avoid_parsing
Feb 20, 2026
Merged

fix: improve getErrorDescFromResponse() performance#4110
logachev merged 5 commits intomainfrom
kirl/retry_avoid_parsing

Conversation

@logachev
Copy link
Contributor

@logachev logachev commented Feb 18, 2026

getErrorDescFromResponse() is very inefficient. Running jfr profiler I noticed that ~55% of CPU-time running query that fetches ~300k rows/10 value each is spent in that function.
Apparently, while it has a model object that inherits from GenericJson, it serializes it & parses json again which is a lot of work when response represents page containing 10k rows.

Judging based on the comment (and looking at available models) the only case when ResponseT contains status.error_result.message is for Job object.

Removed json serialization/parsing and scoped it down to Job object.

@product-auto-label product-auto-label bot added size: s Pull request size is small. api: bigquery Issues related to the googleapis/java-bigquery API. labels Feb 18, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @logachev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a performance enhancement to the BigQueryRetryAlgorithm by optimizing the getErrorDescFromResponse method. Previously, this method would always parse the response into a JsonObject to extract error details. The updated implementation now first checks if the response is already a GenericJson object and, if so, directly accesses its properties to retrieve the error message, thereby bypassing the potentially expensive string parsing operation. This change improves efficiency when handling GenericJson responses.

Highlights

  • Performance Improvement: Optimized the getErrorDescFromResponse() method by avoiding unnecessary JSON string parsing for GenericJson response types.
  • Direct Error Extraction: Implemented direct extraction of error descriptions from GenericJson objects, reducing overhead and improving efficiency.
Changelog
  • google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryRetryAlgorithm.java
    • Added an import for com.google.api.client.json.GenericJson.
    • Modified getErrorDescFromResponse to check if the previousResponse is an instance of GenericJson and extract error details directly from it, improving performance.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces a performance optimization for getErrorDescFromResponse by directly accessing GenericJson responses, which avoids expensive string serialization and re-parsing. However, there is a logic error in the field name used to extract the error message, and the implementation could be more robust regarding null safety and formatting.

@logachev logachev force-pushed the kirl/retry_avoid_parsing branch from 0620ab3 to 8aa0a80 Compare February 18, 2026 23:21
@logachev logachev force-pushed the kirl/retry_avoid_parsing branch from 8aa0a80 to 9341a76 Compare February 18, 2026 23:26
@logachev
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request provides a significant performance improvement to getErrorDescFromResponse() by replacing an inefficient JSON serialization and parsing process with direct object access. The change is well-reasoned and correctly identifies that the error message structure being checked for is specific to Job objects. I have one suggestion to enhance the readability of the new implementation, making the null-checking logic more explicit.

Comment on lines +225 to +230
if (previousResponse instanceof Job) {
Job job = (Job) previousResponse;
ErrorProto error = job.getStatus() != null ? job.getStatus().getErrorResult() : null;
return error != null ? error.getMessage() : null;
}
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This is a great performance improvement. For better readability and to avoid potential maintenance issues with chained ternary operators, consider refactoring this block to use nested if statements. This makes the null-checking logic more explicit and easier to understand at a glance.

    if (previousResponse instanceof Job) {
      Job job = (Job) previousResponse;
      com.google.api.services.bigquery.model.JobStatus status = job.getStatus();
      if (status != null) {
        ErrorProto error = status.getErrorResult();
        if (error != null) {
          return error.getMessage();
        }
      }
    }
    return null;

@logachev logachev added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 18, 2026
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 18, 2026
@logachev logachev marked this pull request as ready for review February 19, 2026 22:12
@logachev logachev requested review from a team as code owners February 19, 2026 22:12
@logachev logachev merged commit 4e0b409 into main Feb 20, 2026
26 checks passed
@logachev logachev deleted the kirl/retry_avoid_parsing branch February 20, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the googleapis/java-bigquery API. size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants